<html><body><pre><script>
function splitMil(n) {
    var sep = (arguments.length == 2) ? arguments[1] : '.';
    n += '';
    if ((n.length) <= 3) { return n };
    return splitMil(n.slice(0,-3),sep) + sep + n.slice(-3);
}   

document.writeln(splitMil(1));
document.writeln(splitMil(12));
document.writeln(splitMil(123));
document.writeln(splitMil(1234));
document.writeln(splitMil(Math.pow(2,15)));
document.writeln(splitMil(Math.pow(2,31), ' '));
document.writeln(splitMil(Math.pow(2,63), ','));

</script></pre></body></html>

